[/size]

[size="3"]1  // Fig. 3.7: fig03_07.cpp
2  // Instantiating multiple objects of the GradeBook class and using
3  // the GradeBook Constructor to specify the course name
4  // when each GradeBook object is created.
5  #include <iostream>
6  using std::cout;
7  using std::endl;
8
9  #include <string> // program uses C++ standard string class
10  using std::string;
11
12  // GradeBook class definition
13  class GradeBook
14  {
15  public:
16     // Constructor initializes courseName with string supplied as argument 
17     GradeBook( string name )                                               
18     {                                                                      
19        setCourseName( name ); // call set function to initialize courseName
20     } // end GradeBook constructor                                         
21
22     // function to set the course name
23     void setCourseName( string name )
24     {
25        courseName = name; // store the course name in the object
26     } // end function setCourseName
27
28     // function to get the course name
29     string getCourseName()
30     {
31        return courseName; // return object's courseName
32     } // end function getCourseName
33
34     // display a welcome message to the GradeBook user
35     void displayMessage()
36     {
37        // call getCourseName to get the courseName
38        cout << "Welcome to the grade book forn" << getCourseName()
39           << "!" << endl;
40     } // end function displayMessage
41  private:
42     string courseName; // course name for this GradeBook
43  }; // end class GradeBook
44
45  // function main begins program execution
46  int main()
47  {
48     // create two GradeBook objects
49     GradeBook gradeBook1( "CS101 Introduction to C++ Programming" );
50     GradeBook gradeBook2( "CS102 Data Structures in C++" );         
51
52     // display initial value of courseName for each GradeBook
53     cout << "gradeBook1 created for course: " << gradeBook1.getCourseName()
54        << "ngradeBook2 created for course: " << gradeBook2.getCourseName()
55        << endl;
56     return 0; // indicate successful termination
57  } // end main[/size]

[size="3"]